<template>
	<view class="animal_login">
		<view class="animal_header">
			<view class="search_header_back">
				<image @click="backGo" src="/static/back.png" mode=""></image>
			</view>
			<view class="animal_header_title">
				<view class="th2">Hi Welcome
				</view>
				<view class="th1">Back </view>
			</view>
			<image aspectFit class="index_header_img" src="/static/login-register.png" mode=""></image>
		</view>
		<view class="animal_main">
			<view class="form">
				<view class="email">
					<text>账号 :</text> <input v-model="acc" placeholder="请输入你的邮箱"
						placeholder-style="font-size:14px;font-weight:100" type="number">
				</view>
				<view class="password">
					<text>密码 :</text><input v-model="password" placeholder="请输入你的密码"
						placeholder-style="font-size:14px;font-weight:100" type="password">
				</view>
				<view class="btn">
					<u-button @click="loginGo" text="登录"></u-button>
					<u-button @click="jumpGo" text="去注册"></u-button>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from "../../api/index.js"
	export default {
		data() {
			return {
				acc: "",
				password: ""
			};
		},
		methods: {
			backGo() {
				uni.switchTab({
					url: "/pages/home/home"
				})
			},
			jumpGo() {
				uni.navigateTo({
					url: "/pages/register/register"
				})
			},
			loginGo() {

				if (this.acc != "" && this.password != "") {
					login(this.acc, this.password).then((content) => {
						let {
							data
						} = content
						console.log(data)

						if (data.code == 200) {
							uni.showToast({
								title: data.msg,
								icon: "success"
							})
							uni.setStorageSync("uid", data.rows[0].id)
							setTimeout(() => {
								uni.switchTab({
									url: "/pages/home/home"
								})
							}, 1500)


						} else {
							uni.showToast({
								title: data.msg,
								icon: "error"
							})
						}

					})
				} else {
					uni.showToast({
						title: "账号或密码不能未空",
						icon: "none"
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		margin: 40px 18px 0;

		.u-button {
			background-color: #a1b275;
			color: white;
			margin-bottom: 20px;
			border-radius: 10px;
		}
	}

	.search_header_back {
		position: absolute;
		top: 10px;
		left: 10px;
		z-index: 1;

		image {

			width: 30px;
			height: 30px;
		}
	}

	.form {
		height: 300px;
		width: 100%;
		margin-top: 60px;

		.email,
		.password {
			display: flex;
			margin: 0 20px;
			padding: 20px 10px;
			margin-bottom: 10px;
			border-bottom: 2px solid #a1b275;

			input {
				margin-left: 10px;
			}
		}
	}

	.animal_login {
		height: 100vh;
		background-color: #a1b275;
	}

	.animal_header {
		width: 100%;
		height: 150px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.index_header_img {
		display: block;
		width: 172px;
		height: 130px;
		margin-right: 20px;
		margin-top: 10px;
		transform: translateY(39px);
	}

	.animal_header_title {
		margin-top: 20px;
		margin-left: 40px;
		color: white;
		line-height: 36px;

		.th2 {
			font-size: 26px;
			font-weight: 100;
		}

		.th1 {
			font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
			font-size: 28px;
			font-weight: 100;
		}
	}

	.animal_main {
		margin-top: 20px;
		border-radius: 32px 32px 0 0;
		background-color: #f3f2f2;
		height: 497px;
		box-sizing: border-box;
		border-top: 3px solid #683931;
	}
</style>